import java.util.Scanner;

public class GuessNumber
{

    public static void main(String[] args)
    {

        Scanner sc = new Scanner(System.in);

        String again;

        do
        {

            int chance = 7;


            System.out.println("猜[1,100]之间的整数");


            // 1.生成答案数字[1,100],
            int answer = (int) (Math.random() * 100 + 1);
            //[0,1) --> (int) [0,99] + 1 = [0,100]

            //System.out.println("answer = " + answer);

            while (chance > 0)
            {

                System.out.println("你还有"+chance+"次机会");

                // 2.接收猜测数字

                int guess = sc.nextInt();
                System.out.println("guess = " + guess);

                // 3.比较答案与猜测数字的大小关系
                if (guess == answer)
                {
                    System.out.println("猜对了");
                    break;
                }
                else if (guess > answer)
                {
                    System.out.println("大了");
                }
                else
                {
                    System.out.println("小了");
                }

                chance -= 1;

            }

            if (chance <= 0)
            {
                System.out.println("你没有机会了,是否重玩?");
            }



            System.out.println("再玩一次吗?[y or n]?");

            again = sc.next();

        }
        while (again.equalsIgnoreCase("y"));


        sc.close();


    }

}